package com.sx.pipeline.wxapi;

import android.widget.Toast;

import com.sx.mvvmlibs.base.BaseApp;
import com.sx.pipeline.R;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

/**
 * @Author: YY
 * @Date: 2021/11/23
 * @Describe: TODO
 */
public class WxUtils {

    private final IWXAPI iwxapi;

    public WxUtils() {
        iwxapi = WXAPIFactory.createWXAPI(BaseApp.getInstance(), null);
        // 将该app注册到微信
        iwxapi.registerApp(BaseApp.getInstance().getString(R.string.wx_app_id));
    }

    public void auth() {
        //先判断用户手机是否安装了微信客户端
        if (!iwxapi.isWXAppInstalled()) {
            Toast.makeText(BaseApp.getInstance(), "您的设备未安装微信客户端", Toast.LENGTH_SHORT).show();
        } else {
            //向微信开放平台发起请求
            final SendAuth.Req req = new SendAuth.Req();
            req.scope = "snsapi_userinfo";
            req.state = "wechat_sdk_demo_test";
            iwxapi.sendReq(req);
        }
    }

}
